﻿using System;
using System.Text;
using System.Reflection;
using System.Collections.Generic;
using Demo_G.O.S.E.ServerEngine.Item;
using System.Diagnostics;

namespace Demo_G.O.S.E.ServerEngine.Treasure
{
    /// <summary>
    /// 
    /// </summary>
    public class Loot
    {
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        ConstructorInfo m_Constructor = null;
        #endregion

        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        /// <summary>
        /// 
        /// </summary>
        /// <param name="type"></param>
        /// <param name="fProbability"></param>
        public Loot( Type type, float fProbability )
        {
            ConstructorInfo[] l_ConstructorInfoArray = type.GetConstructors();
            foreach ( ConstructorInfo l_ConstructorInfo in l_ConstructorInfoArray )
            {
                ParameterInfo[] l_ParameterInfoArray = l_ConstructorInfo.GetParameters();
                if ( l_ParameterInfoArray.Length == 0 )
                {
                    m_Constructor = l_ConstructorInfo;
                    break;
                }
            }

            m_fProbability = fProbability;

            if ( m_Constructor == null )
                Debug.WriteLine( "Loot.Loot(...) - m_Constructor == null error({0})!", type.ToString() );
        }
        #endregion

        #region zh-CHS 属性 | en Properties
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        float m_fProbability = 0.0f;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        public float Probability
        {
            get { return m_fProbability; }
        }
        #endregion

        #region zh-CHS 方法 | en Method
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public BaseItem Instance()
        {
            if ( m_Constructor == null )
            {
                Debug.WriteLine( "Loot.Instance(...) - m_Constructor == null error!" );
                return null;
            }

            return m_Constructor.Invoke( null ) as BaseItem;
        }
        #endregion
    }
}

